$(function () {
  $("#Buser").focus();
  //记住密码
  var logInfo = JSON.parse(localStorage.getItem("logInfo") || "{}");
  if (logInfo.checked) {
    $("#Buser").val(logInfo.login);
    $("#Bpwd").val(logInfo.pwd);
    $("#remPwd").prop("checked", true);
  }
  // else {
  //   $("#Buser").val("");
  //   $("#Bpwd").val("");
  // }

  // 点击登录
  $(".btnLogin").off("click").on("click", function () {
    var Buser = $("#Buser").val();
    var Bpwd = $("#Bpwd").val();
    $(".btnLogin").attr("disabled","disabled");

    if (Buser == "" || Bpwd == "") {
      $(".btnLogin").attr("disabled",false);
      App.msg("请输入帐号/密码");
    } else {
      App.ajax("ss_wx/user_login", "post", {
        login: Buser,
        password: Bpwd
      }, function (data) {
        console.log('data====', data);
        if (data.flag == true) {
          if ($("#remPwd").is(":checked")) {
            var logInfo = {
              "login": Buser,
              "pwd": Bpwd,
              "checked": true
            };
            localStorage.setItem("logInfo", JSON.stringify(logInfo));
          } else {
            localStorage.setItem("logInfo", JSON.stringify({
              "login": Buser,
              "checked": false
            }));
          }
          localStorage.setItem("token", data.token);
          localStorage.setItem("pos_group_id", data.pos_group_id);
          localStorage.setItem("user_id", data.user_id);
          // localStorage.setItem("print_num", data.print_num);
          App.msg("登录成功", function () {
            setTimeout(function () {
              window.location.href = "pages/Table.html";
            }, 1000);
            window.samfeng.setJPRegistrationId(JSON.stringify(data));

          });
        } else {
          $(".btnLogin").attr("disabled",false);
          App.msg(data.msg);
        }
      }, "login")
    };

    setTimeout(function () {
      $(".btnLogin").attr("disabled",false);
    }, 2000)
  });
  //点击系统设置
  $(".XTSZ").off("click").on("click", function () {
    window.samfeng.printPosSET("点击系统设置");
    /*
    setTimeout(function () {
      location.reload();
    }, 1000)
    */
  })
})